<script setup lang="ts">
	import { ref } from 'vue'
	import msgItem from './compontents/msgItem.vue'

	const Tabs = ref([
		{ State: 0, title: '优惠消息' },
		{ State: 1, title: '平台公告' },
	])

	const query = defineProps<{
		type : string
	}>()

	const activeIndex = ref(Tabs.value.findIndex((v) => v.State === Number(query.type)))
</script>

<template>
	<view class="viewport">
		<!-- tabs -->
		<view class="tabs">
			<text class="item" v-for="(item, index) in Tabs" :key="item.title" @tap="activeIndex = index">
				{{ item.title }}
			</text>
			<view class="cursor" :style="{ left: activeIndex * 50 + '%' }"></view>
		</view>
		<swiper style="height: calc(100vh - 40px );" :current="activeIndex"
			@change="activeIndex = $event.detail.current">
			<swiper-item v-for="item in Tabs" :key="item.title" style="height: calc(100vh - 40px );">
				<scroll-view scroll-y class="orders">
					<msgItem :State="item.State" />
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<style scoped lang="scss">
	page {
		height: 100%;
		overflow: hidden;
	}

	.viewport {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: #f7f7f7;
	}

	// tabs
	.tabs {
		display: flex;
		justify-content: space-around;
		line-height: 60rpx;
		margin: 0 10rpx;
		background-color: #fff;
		box-shadow: 0 4rpx 6rpx rgba(240, 240, 240, 0.6);
		position: relative;
		z-index: 9;

		.item {
			flex: 1;
			text-align: center;
			padding: 20rpx;
			font-size: 28rpx;
			color: #262626;
		}

		.cursor {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 50%;
			height: 6rpx;
			padding: 0 50rpx;
			background-color: $uni-color-primary;
			/* 过渡效果 */
			transition: all 0.4s;
		}
	}
</style>